﻿// DlgMesSet.cpp : 实现文件
#include "stdafx.h"
#include "SCIMes.h"
#include "DlgMesSet.h"
#include "afxdialogex.h"
#include "DlgInfo.h"
// CDlgMesSet 对话框

IMPLEMENT_DYNAMIC(CDlgMesSet, CDialogEx)

CDlgMesSet::CDlgMesSet(CWnd* pParent /*=NULL*/)
	: CDialogEx(CDlgMesSet::IDD, pParent)
	, m_strLineCode(_T(""))
	, m_strSectionCode(_T(""))
	, m_strEMSN(_T(""))
	, m_strEMName(_T(""))
	, m_strLocalFilePath(_T(""))
	, m_strSeverFilePath(_T(""))
	, m_RealMes(NULL)
	, m_strFactory(_T(""))
	, m_strEQM(_T(""))	
	, m_strLocalFile(_T(""))
	, m_iThreadNumber(5)
	, m_iThreadCount(0)
	, m_pSendInfo(NULL)
	, m_isSendHttpMessage(FALSE)
	, m_bSendOK(FALSE)
	, m_bSendNG(FALSE)
	, m_bSendNGCrop(FALSE)
	, m_bSendCover(FALSE)
	, m_bRename(FALSE)
	, m_strLocalRootPath(_T(""))
	, m_strRootPathSymbol(_T(""))
	, m_strRenameSymbol(_T(""))
	, m_iMod(0)
	, m_iLenght(0)
	,m_bSendFile(FALSE)
	, m_iIntervalMinute(0)
	, m_Edit_nLogSaveDays(0)
{
	m_iThreadCount = m_iThreadNumber;

	m_vecFilePathList.clear();

	m_Edit_cstrResourceCode = _T("");
	m_Edit_UserName = _T("");
	m_Edit_UserPassword = _T("");
	m_Edit_cstrOperatorID = _T("");
	m_Edit_cstrOperatorPassword = _T("");
	m_Edit_nHeartBeatTime = 0.0;
	m_Edit_cstrFtpServerAddr = _T("");
	m_Edit_cstrFtpServerID = _T("");
	m_Edit_cstrMesServerAddr = _T("");
	m_Edit_nMesServerPort = 0;
}

CDlgMesSet::~CDlgMesSet()
{
}

void CDlgMesSet::DoDataExchange(CDataExchange* pDX)
{
	CDialogEx::DoDataExchange(pDX);
	DDX_Text(pDX, IDC_EDIT_LINECODE, m_strLineCode);
	DDX_Text(pDX, IDC_EDIT_SECTIONCODE, m_strSectionCode);
	DDX_Text(pDX, IDC_EDIT_EMSN, m_strEMSN);
	DDX_Text(pDX, IDC_EDIT_EMNAME, m_strEMName);
	DDX_Text(pDX, IDC_EDIT_LOCALFILEPATH, m_strLocalFilePath);
	DDX_Text(pDX, IDC_EDIT_SEVERFILEPATH, m_strSeverFilePath);
	DDX_Text(pDX, IDC_EDIT_FACTORY, m_strFactory);
	DDX_Text(pDX, IDC_EDIT_EQM, m_strEQM);	
	DDX_Text(pDX, IDC_EDIT_LOCALFILE, m_strLocalFile);
	DDX_Control(pDX, IDC_EDIT_THREADNUMBER, m_Edit_ThreadNumber);
	DDX_Check(pDX, IDC_CHECK_SENDHTTP, m_isSendHttpMessage);
	DDX_Control(pDX, IDC_CHECK_SENDOK, m_check_sendOK);
	DDX_Control(pDX, IDC_CHECK_SENDNG, m_check_sendNG);
	DDX_Control(pDX, IDC_CHECK_SENDNGCROP, m_check_sendNGCrop);
	DDX_Control(pDX, IDC_CHECK_RENAME, m_check_rename);
	DDX_Control(pDX, IDC_CHECK_SENDCOVER, m_check_sendCover);
	DDX_Text(pDX, IDC_EDIT_ROOTPATHSYMBOL, m_strRootPathSymbol);
	DDX_Text(pDX, IDC_EDIT_LOCALROOTPATH, m_strLocalRootPath);
	DDX_Text(pDX, IDC_EDIT_RENAMESYMBOL, m_strRenameSymbol);
	DDX_Control(pDX, IDC_CHECK_SENDFILE, m_check_sendFile);
	DDX_Text(pDX, IDC_EDIT_INTERVALMINUTE, m_iIntervalMinute);
	DDV_MinMaxInt(pDX, m_iIntervalMinute, 1, 120);
	DDX_Control(pDX, IDC_COMBO_LOGSAVETYPE, m_COMBO_logType);
	DDX_Text(pDX, IDC_EDIT_RESOURCECODE, m_Edit_cstrResourceCode);
	DDX_Text(pDX, IDC_EDIT_USERNAME, m_Edit_UserName);
	DDX_Text(pDX, IDC_EDIT_USERPASSWORD, m_Edit_UserPassword);
	DDX_Text(pDX, IDC_EDIT_OPERATORID, m_Edit_cstrOperatorID);
	DDX_Text(pDX, IDC_EDIT_OPRERATORPASSWORD, m_Edit_cstrOperatorPassword);
	DDX_Text(pDX, IDC_EDIT_HEARTBEATTIME, m_Edit_nHeartBeatTime);
	DDV_MinMaxDouble(pDX, m_Edit_nHeartBeatTime, 0.5, 1000);
	DDX_Text(pDX, IDC_EDIT_LOGSAVEDAYS, m_Edit_nLogSaveDays);
	DDV_MinMaxInt(pDX, m_Edit_nLogSaveDays, 0, 365);
	DDX_Text(pDX, IDC_EDIT_FTPSERVERADDR, m_Edit_cstrFtpServerAddr);
	DDX_Text(pDX, IDC_EDIT_FTPSERVERID, m_Edit_cstrFtpServerID);
	DDX_Text(pDX, IDC_EDIT_FTPSERVERPASSWORD, m_Edit_cstrFtpServerPassword);
	DDX_Text(pDX, IDC_EDIT_MESSERVERADDR, m_Edit_cstrMesServerAddr);
	DDX_Text(pDX, IDC_EDIT_MESSERVERPORT, m_Edit_nMesServerPort);
}


BEGIN_MESSAGE_MAP(CDlgMesSet, CDialogEx)
	ON_BN_CLICKED(IDOK, &CDlgMesSet::OnBnClickedOk)
	ON_BN_CLICKED(IDC_BUTTON_OPEN, &CDlgMesSet::OnBnClickedButtonOpen)
	ON_EN_KILLFOCUS(IDC_EDIT_SEVERFILEPATH, &CDlgMesSet::OnEnKillfocusEditSeverfilepath)
	ON_BN_CLICKED(IDC_BUTTON_SEND, &CDlgMesSet::OnBnClickedButtonSend)
	ON_BN_CLICKED(IDCANCEL, &CDlgMesSet::OnBnClickedCancel)
	ON_BN_CLICKED(IDC_BUTTON_SAVE, &CDlgMesSet::OnBnClickedButtonSave)
	ON_BN_CLICKED(IDC_BUTTON_SELECT, &CDlgMesSet::OnBnClickedButtonSelect)
	ON_MESSAGE(WM_UPDATE_MESSAGE, OnUpdateMessage)
	ON_BN_CLICKED(IDC_BUTTON_RENAME, &CDlgMesSet::OnBnClickedButtonRename)
	ON_BN_CLICKED(IDC_BUTTON_SINGLETHREAD, &CDlgMesSet::OnBnClickedButtonSinglethread)
	ON_BN_CLICKED(IDC_BUTTON_MULTITHREAD, &CDlgMesSet::OnBnClickedButtonMultithread)
	ON_EN_KILLFOCUS(IDC_EDIT_THREADNUMBER, &CDlgMesSet::OnEnKillfocusEditThreadnumber)
	ON_BN_CLICKED(IDC_CHECK_SENDHTTP, &CDlgMesSet::OnBnClickedCheckSendhttp)
	ON_BN_CLICKED(IDC_CHECK_SENDOK, &CDlgMesSet::OnBnClickedCheckSendok)
	ON_BN_CLICKED(IDC_CHECK_SENDNG, &CDlgMesSet::OnBnClickedCheckSendng)
	ON_BN_CLICKED(IDC_CHECK_SENDNGCROP, &CDlgMesSet::OnBnClickedCheckSendngcrop)
	ON_BN_CLICKED(IDC_CHECK_RENAME, &CDlgMesSet::OnBnClickedCheckRename)
	ON_BN_CLICKED(IDC_CHECK_SENDCOVER, &CDlgMesSet::OnBnClickedCheckSendcover)
	ON_BN_CLICKED(IDC_BUTTON_SELECTROOTPATH, &CDlgMesSet::OnBnClickedButtonSelectrootpath)
	ON_BN_CLICKED(IDC_BUTTON_UNRENAME, &CDlgMesSet::OnBnClickedButtonUnrename)
	ON_BN_CLICKED(IDC_CHECK_SENDFILE, &CDlgMesSet::OnBnClickedCheckSendfile)
	ON_BN_CLICKED(IDC_BUTTON_RECIPESET, &CDlgMesSet::OnBnClickedButtonRecipeset)
	ON_BN_CLICKED(IDC_BUTTON_CHECHRECIPEVERSION, &CDlgMesSet::OnBnClickedButtonChechrecipeversion)
END_MESSAGE_MAP()


// CDlgMesSet 消息处理程序


BOOL CDlgMesSet::OnInitDialog()
{
	CDialogEx::OnInitDialog();

	// TODO:  在此添加额外的初始化

	InitUI();
	
	return TRUE;  // return TRUE unless you set the focus to a control
	// 异常: OCX 属性页应返回 FALSE
}


void CDlgMesSet::OnBnClickedOk()
{
	// TODO: 在此添加控件通知处理程序代码
	

}


void CDlgMesSet::OnBnClickedButtonOpen()
{
	// TODO: 在此添加控件通知处理程序代码
	TCHAR szFilter[] = _T("所有文件(*.*)|*.*||"); 
	CFileDialog FileDlg(TRUE, _T("*.*"), NULL, 0, szFilter, this); 
	if(IDOK == FileDlg.DoModal())
	{
		m_strLocalFilePath = FileDlg.GetPathName(); 
		m_strFileName = FileDlg.GetFileName();
	}
	else
	{
		return;
	}
	SYSTEMTIME CurSysTime;
	GetLocalTime(&CurSysTime);
	m_strSeverFilePath.Format(_T("%s/%s/Data/%d/%d/%d/%s"),m_RealMes->GetFtpAddr(),m_strEMSN,
			CurSysTime.wYear,CurSysTime.wMonth,CurSysTime.wDay,m_strFileName);
	UpdateData(FALSE);	

	
}


void CDlgMesSet::OnEnKillfocusEditSeverfilepath()
{
	// TODO: 在此添加控件通知处理程序代码
	UpdateData(TRUE);
	MessageBox(m_strSeverFilePath,NULL,NULL);
}





void CDlgMesSet::OnBnClickedButtonSend()
{
	// TODO: 在此添加控件通知处理程序代码
	CString strFilePath;
	CString strRemoteFile;	//服务器文件路径
	SYSTEMTIME CurSysTime;
	CString strSpendTime,strMessage;
	GetLocalTime(&CurSysTime);
	{
		strFilePath.Format(_T("%s/Data/%04d年/%02d月/%02d日/%s"),m_strEMSN,CurSysTime.wYear,CurSysTime.wMonth,CurSysTime.wDay,m_strFileName);

		strRemoteFile.Format(_T("%s/%s"),m_RealMes->GetFtpAddr(),strFilePath);

		if (m_RealMes->m_bSendCover && !m_RealMes->IsUpload(m_strLocalFilePath))
		{
			strMessage.Format(_T("文件：%s已经上传过，如果要再次上传，请关闭 [过滤已发送文件] 选项！"),m_strLocalFilePath);

			MessageBox(strMessage);

			return;
		}
		
		SYSTEMTIME m_beginTime;

		SYSTEMTIME m_EndTime;

		GetLocalTime(&m_beginTime);

		int nRet = m_RealMes->FtpUpload(strRemoteFile,m_strLocalFilePath);  //C:\Users\xuxh\Desktop\111\0.bmp

		GetLocalTime(&m_EndTime);

		__int64 iSpeedTime = TimeDiff(m_EndTime,m_beginTime);

		MillisecondToHours(iSpeedTime,strSpendTime);

		strMessage.Format(_T("一共完成上传%d个文件，一共耗时%s"),1,strSpendTime);

		MessageBox(strMessage);

		if (CURLE_OK != nRet)
		{
			CString strMessage;
			strMessage.Format(_T("FtpUpload错误！\n错误码：%d"),nRet);
			MessageBox(strMessage,NULL,NULL);
		}

		m_RealMes->WriteUploadTuple();

	}


	neb::CJsonObject oJson;
	neb::CJsonObject oJson1;
	neb::CJsonObject oJson2;

	neb::CJsonObject oJsonPackage;
	neb::CJsonObject oJsonOKImg;
	neb::CJsonObject oJsonNGImg;
	neb::CJsonObject oJsonResult;
	
	oJson2.Add("IsOnline",true);
	oJson2.Add("LineCode",m_strLineCode.GetBuffer());
	oJson2.Add("SectionCode",m_strSectionCode.GetBuffer());
	oJson2.Add("EquipmentCode",m_strEMSN.GetBuffer());
	oJson2.Add("Timestamp","2019-12-30T09:07:11.8325241+08:00");
	
	oJsonOKImg.Add("FilePath","A801/ZYDBM01/深圳海目星/JT-PH1-HC-BM-CPJ001/Image/2020/03/23/AAA.jpg");
	oJsonOKImg.Add("IsOk","true");
	oJsonOKImg.Add("ProductBarcode","333");
	oJsonOKImg.Add("Timestamp","2020-03-23T15:01:14.6810138+08:00");

	oJsonNGImg.Add("FilePath","A801/工序Y/xx设备厂家/设备Z/Image/2020/03/23/BBB.jpg");
	oJsonNGImg.Add("IsOk","false");
	oJsonNGImg.Add("ProductBarcode","BBB");
	oJsonNGImg.Add("Timestamp","2020-03-23T15:01:14.6810138+08:00");

	oJsonResult.Add("FilePath","A801/工序Y/xx设备厂家/设备Z/Data/2020/03/23/CCC.csv");
	oJsonResult.Add("ProductBarcode","CCC");
	oJsonResult.Add("Timestamp","2020-03-23T15:01:14.6810138+08:00");

	oJsonPackage.AddEmptySubArray("Files");
	oJsonPackage["Files"].Add(oJsonOKImg);
	oJsonPackage["Files"].Add(oJsonNGImg);
	oJsonPackage["Files"].Add(oJsonResult);

	oJsonPackage.Add("LineCode",m_strLineCode.GetBuffer());
	oJsonPackage.Add("SectionCode",m_strSectionCode.GetBuffer());
	oJsonPackage.Add("EquipmentCode",m_strEMSN.GetBuffer());
	oJsonPackage.Add("Timestamp","2020-03-23T15:01:14.6739909+08:00");

	std::string strF = "[" + oJsonPackage.ToString() + "]";

	strF = AsciiToUtf8(strF);

	std::string strRespon;

	std::string strSendMessage;

	std::string strSendMessageUTF8;

	GetLocalTime(&CurSysTime);

	m_RealMes->GetSendFileJson(strRemoteFile,strSendMessage,CurSysTime);

	strSendMessageUTF8 = AsciiToUtf8(strSendMessage);
/*
	int iRet = m_RealMes->MESReportCcdFilesUploadCompleted((CString)strSendMessageUTF8.c_str(),strRespon);

	if (200 != iRet)
	{
		CString strException;

		CString strMessage;

		strMessage.Format(_T("MESReportCcdFilesUploadCompleted:%d:%s\n%s\n"),iRet,strRespon.c_str(),strSendMessage.c_str());

		m_RealMes->m_sInit.pLogView->DoSomething("EXCEPTION", (void*)(LPCSTR)strMessage,NULL);
	}
*/
	if (m_isSendHttpMessage)
	{
		int iRet;

		iRet = m_RealMes->MesReportFileUploadCompleted(strRemoteFile);

	}
	
}


void CDlgMesSet::OnBnClickedCancel()
{
	// TODO: 在此添加控件通知处理程序代码
	CDialogEx::OnCancel();
}


void CDlgMesSet::OnBnClickedButtonSave()
{
	Save();
}


void CDlgMesSet::OnBnClickedButtonSelect()
{
	// TODO: 在此添加控件通知处理程序代码

	TCHAR           szFolderPath[MAX_PATH] = {0};  
	CString         strFolderPath = TEXT("");  
	 
	BROWSEINFO      sInfo;  
	::ZeroMemory(&sInfo, sizeof(BROWSEINFO));  
	sInfo.pidlRoot   = 0;  
	sInfo.lpszTitle   = _T("");		//请选择处理结果存储路径
	sInfo.ulFlags   = BIF_RETURNONLYFSDIRS|BIF_EDITBOX|BIF_DONTGOBELOWDOMAIN;  
	sInfo.lpfn     = NULL;  
	
		     // 显示文件夹选择对话框  
	LPITEMIDLIST lpidlBrowse = ::SHBrowseForFolder(&sInfo);   
	if (lpidlBrowse != NULL)  
		{  
			       // 取得文件夹名  
			 if (::SHGetPathFromIDList(lpidlBrowse,szFolderPath))    
				{  
					strFolderPath = szFolderPath;  
				}  
		}  
	 if(lpidlBrowse != NULL)  
		{  
			 ::CoTaskMemFree(lpidlBrowse);  
		} 
	 m_strLocalFile = strFolderPath;
	 UpdateData(FALSE);
//	 MessageBox(strFolderPath,NULL,NULL);

//	 BroseAllFiles(strFolderPath);

		 
}

/*
void CDlgMesSet::BroseAllFiles(CString filepath)
{
	//检测路径是否正确并添加必要信息
	if (filepath == _T(""))
	{
		return;
	}
	else 
	{
		CString strTem = filepath.Right(1);
		if (filepath.Right(1) != _T(""))
		{
			filepath += _T("\\");
		}
		filepath += _T("*.*");
	}

	//递归枚举文件夹下的内容
	CFileFind find;
	CString strpath;
	CString str_fileName;
	CString fullname;
	BOOL IsFind = find.FindFile(filepath);

	while (IsFind)
	{
		IsFind = find.FindNextFile();
		strpath = find.GetFilePath();

		if (find.IsDirectory() && !find.IsDots())
		{
			BroseAllFiles(strpath);
		}
		else if (!find.IsDirectory() && !find.IsDots())
		{
			str_fileName = find.GetFileName();
			if (str_fileName.Right(3) == _T("bmp")) //如果后缀是bmp文件才处理
			{
				fullname = strpath + str_fileName;
				MessageBox(fullname,NULL,NULL);
			}
			if (str_fileName.Right(3) == _T("csv")) //如果后缀是csv文件才处理
			{
				fullname = strpath + str_fileName;
				MessageBox(fullname,NULL,NULL);
			}
			if (str_fileName.Right(3) == _T("xls")) //如果后缀是csv文件才处理
			{
				fullname = strpath + str_fileName;
				MessageBox(fullname,NULL,NULL);
			}
		}
		else 
		{
			continue;
		}
	}
}
*/

/*

void CDlgMesSet::GetFilePath(std::vector<CString>& vFilePathList,CString strDir)
{
	CFileFind finder;
	BOOL isNotEmpty = finder.FindFile(strDir+_T("*.*"));//总文件夹，开始遍历 
	while(isNotEmpty)
	{
		isNotEmpty = finder.FindNextFile();//查找文件 
		CString filename = finder.GetFilePath();//获取文件的路径，可能是文件夹，可能是文件 
		if (!(finder.IsDirectory()))
		{										//如果是文件则加入文件列表
			vFilePathList.push_back(filename);//将一个文件路径加入容器
		} 
		else
		{													//递归遍历用户文件夹，跳过非用户文件夹
			if (!(finder.IsDots()||finder.IsHidden()||finder.IsSystem()||finder.IsTemporary()||finder.IsReadOnly()))
			{
				GetFilePath(vFilePathList,filename+_T("/"));
			}
		}
	}
}

*/

int CDlgMesSet::FtpUploadFile(CString & strFullFilePath)
{
	CString strServerFilePath;

	m_RealMes->LocalFilePathToServerFilePath(strFullFilePath,strServerFilePath,m_strRootPathSymbol);
	
	int nRet = m_RealMes->FtpUpload(strServerFilePath,strFullFilePath/*本地路径*/);  //C:\Users\xuxh\Desktop\111\0.bmp

	if ( nRet > 0)
	{
		CString strException;

		strException.Format(_T("FtpUpload错误！\t错误码：%d"),nRet);

	//	m_RealMes->m_sInit.pLogView->DoSomething("EXCEPTION",(void*)(LPCTSTR)strException,NULL);

		m_RealMes->Log(strException);

		return nRet;
	}

	if (m_isSendHttpMessage)
	{
		m_RealMes->MesReportFileUploadCompleted(strServerFilePath);
	}
	
	return nRet;
}
UINT CDlgMesSet::ThreadProc(LPVOID lpVoid)
{
	CDlgMesSet *lpThis = (CDlgMesSet*)lpVoid;
	int i = 0;
	std::vector<CString> vecFilePathList =lpThis->m_vecFilePathList;

	int j = vecFilePathList.size();

	for (std::vector<CString>::iterator iter = vecFilePathList.begin();iter != vecFilePathList.end();iter++)
	{
		i++;
		if (lpThis->m_RealMes->m_bSendCover)			//是否过滤已上传文件
		{
			if (!lpThis->m_RealMes->IsUpload(*iter))		//是否上传检测
			{
				lpThis->PostMessageA(WM_UPDATE_MESSAGE ,NULL,NULL);

				continue;
			}
		}

		lpThis->m_RealMes->FtpUploadFile(*iter);

		lpThis->PostMessageA(WM_UPDATE_MESSAGE ,NULL,NULL);
	}

	lpThis->m_RealMes->WriteUploadTuple();

	return	0;
}

UINT CDlgMesSet::ThreadProcMulti(LPVOID lpVoid)
{
	SendInfo *lpSendInfo = (SendInfo*)lpVoid;
	
	std::vector<CString> vecFilePathList =lpSendInfo->pDlg->m_vecFilePathList;

	std::vector<CString>::iterator iterStart ,iterEnd;
	
	iterStart	= vecFilePathList.begin() + lpSendInfo->id*lpSendInfo->iLenght;

	if (lpSendInfo->id == THREADCOUNT - 1)
	{
		iterEnd = vecFilePathList.end();
	}
	else
	{
		iterEnd = vecFilePathList.begin() + (lpSendInfo->id + 1 ) * lpSendInfo->iLenght ;
	}

	CString strMessage;

	SYSTEMTIME currentTime;

	GetLocalTime(&currentTime);

	int iStart,iLenght;

	iStart = iterStart - vecFilePathList.begin();

	iLenght = iterEnd - iterStart;

	strMessage.Format(_T("%4d年%2d月%2d日%2d时%2d分%2d秒%d毫秒\t线程号：\t%d\t起始：\t%d\t长度：\t%d\n"),currentTime.wYear,currentTime.wMonth,currentTime.wDay,currentTime.wHour,currentTime.wMinute,
		currentTime.wSecond,currentTime.wMilliseconds,lpSendInfo->id,iStart,iLenght);

	lpSendInfo->pDlg->m_RealMes->m_record.writeAssignmentFile(strMessage);

	int i = lpSendInfo->id;

	int j =0;

	for (std::vector<CString>::iterator iter = iterStart;iter != iterEnd ;iter++)
	{
		j++;

		lpSendInfo->pDlg->FtpUploadFile(*iter);

		lpSendInfo->pDlg->PostMessageA(WM_UPDATE_MESSAGE ,NULL,NULL);
	}

	return	0;
}


UINT CDlgMesSet::ThreadProcDynamic(LPVOID lpVoid)
{
	SendInfo *lpSendInfo = (SendInfo*)lpVoid;

	std::vector<CString> vecFilePathList =lpSendInfo->pDlg->m_vecFilePathList;

	std::vector<CString>::iterator iterStart ,iterEnd;

	iterStart	= vecFilePathList.begin() + lpSendInfo->iSum - lpSendInfo->iLenght;

	iterEnd = iterStart + lpSendInfo->iLenght;
	
	CString strMessage;

	SYSTEMTIME currentTime;

	GetLocalTime(&currentTime);

	int iStart,iLenght;

	iStart = iterStart - vecFilePathList.begin();

	iLenght = iterEnd - iterStart;

	strMessage.Format(_T("%4d年%2d月%2d日%2d时%2d分%2d秒%d毫秒\t线程号：\t%d\t起始：\t%d\t长度：\t%d\n"),currentTime.wYear,currentTime.wMonth,currentTime.wDay,currentTime.wHour,currentTime.wMinute,
		currentTime.wSecond,currentTime.wMilliseconds,lpSendInfo->id,iStart,iLenght);

	lpSendInfo->pDlg->m_RealMes->m_record.writeAssignmentFile(strMessage);

	int i = lpSendInfo->id;

	int j =0;

	for (std::vector<CString>::iterator iter = iterStart;iter != iterEnd ;iter++)
	{
		j++;

		if (lpSendInfo->pDlg->m_RealMes->m_bSendCover)			//是否过滤已上传文件
		{
			if (!lpSendInfo->pDlg->m_RealMes->IsUpload(*iter))		//是否上传检测
			{
				lpSendInfo->pDlg->PostMessageA(WM_UPDATE_MESSAGE ,NULL,NULL);

				continue;
			}
		}

		lpSendInfo->pDlg->FtpUploadFile(*iter);

		lpSendInfo->pDlg->PostMessageA(WM_UPDATE_MESSAGE ,NULL,NULL);
	}

	lpSendInfo->pDlg->m_RealMes->WriteUploadTuple();

	return	0;
}

UINT CDlgMesSet::ThreadCheckRecipeVersion(LPVOID lpVoid)
{
	if (!lpVoid)
	{
		return 0;
	}
	CDlgMesSet* pDlg = (CDlgMesSet*) lpVoid;
	pDlg->CheckRecipeVersion();

	return 0;
}

LRESULT CDlgMesSet::OnUpdateMessage(WPARAM wParam, LPARAM lParam)
{
	
	dlgInfo.m_iComplete ++;
	dlgInfo.m_strUploadInfo.Format(_T("一共%d个文件：已经上传%d个文件"),dlgInfo.m_iCount,dlgInfo.m_iComplete);
	dlgInfo.m_staticInfo.SetWindowTextA(dlgInfo.m_strUploadInfo);
	if (dlgInfo.m_iComplete == dlgInfo.m_iCount)
	{
		CString strMessage;

		strMessage.Format(_T("上传完毕，一共上传%d个文件！"),dlgInfo.m_iComplete);

		dlgInfo.PostMessage(WM_CLOSE ,NULL,NULL);

		m_vecFilePathList.clear();

		if (NULL != m_pSendInfo)
		{
			delete[] m_pSendInfo;

			m_pSendInfo = NULL;
		}
	}
	
	return 0;
}


void CDlgMesSet::OnBnClickedButtonRename()
{
	// TODO: 在此添加控件通知处理程序代码
	TCHAR szFilter[] = _T("所有文件(*.*)|*.*||"); 
	CFileDialog FileDlg(TRUE, _T("*.*"), NULL, 0, szFilter, this); 
	CString	strFullFilePath;	//带路径文件全名
	CString strFilePath;		//文件夹路径
	CString strFileExtendName;	//文件扩展名
	CString strFileName;		//文件名，带扩展名
	CString strFile;			//文件名，不带扩展名
	CString strNewFilePath;		//新文件 带路径全名
	CString strNewFile;			//新文件名
	
	
	if(IDOK != FileDlg.DoModal())
	{
		return;
	}
	strFullFilePath = FileDlg.GetPathName(); 
	
	RenameFile(strFullFilePath,m_strRenameSymbol);
}


void CDlgMesSet::OnBnClickedButtonSinglethread()
{
	std::vector<CString> vecFilePathList;

	 CString strMessage;

	 CString strLocalFilePath;

	 strLocalFilePath.Format(_T("%s"),m_strLocalFile);

	 if (_T("")==m_strLocalFile)
	 {
		 return;
	 }

//	 m_RealMes->GetFilePath(vecFilePathList,strLocalFilePath,m_bSendOK,m_bSendNG,m_bSendNGCrop,m_bSendCover);

	 m_RealMes->GetFilePath(vecFilePathList,strLocalFilePath,m_bSendOK,m_bSendNG,m_bSendNGCrop);
	 
	 int iCount = vecFilePathList.size();

	 strMessage.Format("共有%d个文件,确认要上传全部文件？",iCount);	 

	 if (IDYES != MessageBox(strMessage,_T("请确认是否上传文件夹"),MB_ICONEXCLAMATION|MB_YESNO ))
	 {
		 return;
	 }
	 
	 dlgInfo.m_iCount = iCount;

	 m_vecFilePathList = vecFilePathList;

	 ::CreateThread(NULL,NULL,(LPTHREAD_START_ROUTINE)ThreadProc,this,NULL,NULL);

	 dlgInfo.DoModal();
}


void CDlgMesSet::OnBnClickedButtonMultithread()		//动态多线程发送
{
	std::vector<CString> vecFilePathList;

	SYSTEMTIME currentTime;

	CString strMessage;

	CString strLocalFilePath;

	strLocalFilePath.Format(_T("%s"),m_strLocalFile);

	int iLenght = 0;

	int iMod = 0;

	int iSum = 0;

	if (_T("")==m_strLocalFile)
	{
		return;
	}

//	 m_RealMes->GetFilePath(vecFilePathList,strLocalFilePath,m_bSendOK,m_bSendNG,m_bSendNGCrop,m_bSendCover);

	 m_RealMes->GetFilePath(vecFilePathList,strLocalFilePath,m_bSendOK,m_bSendNG,m_bSendNGCrop);

	int iCount = vecFilePathList.size();

	strMessage.Format("共有%d个文件,确认要上传全部文件？",iCount);

	if (IDYES != MessageBox(strMessage,_T("请确认是否上传文件夹"),MB_ICONEXCLAMATION|MB_YESNO ))
	{
		return;
	}

	dlgInfo.m_iCount = iCount;

	m_vecFilePathList = vecFilePathList;

	GetLocalTime(&currentTime);

	strMessage.Format(_T("%4d年%2d月%2d日%2d时%2d分%2d秒%d毫秒\t线程总数：\t%d\t文件数目：\t%d\n"),currentTime.wYear,currentTime.wMonth,currentTime.wDay,currentTime.wHour,currentTime.wMinute,
		currentTime.wSecond,currentTime.wMilliseconds,m_iThreadCount,iCount);

	m_RealMes->m_record.writeAssignmentFile(strMessage);

	m_pSendInfo = new SendInfo[m_iThreadCount];

	m_iLenght = iCount /m_iThreadCount;

	m_iMod = iCount % m_iThreadCount;

	iLenght = m_iLenght;

	iMod = m_iMod;

	for (int i = 0; i < m_iThreadCount ;i++)
	{
		m_pSendInfo[i].id = i;

		m_pSendInfo[i].pDlg = this;

		if (iMod > 0)
		{
			m_pSendInfo[i].iLenght = iLenght + 1;
		}
		else
		{
			m_pSendInfo[i].iLenght = iLenght ;
		}

		iMod--;

		iSum += m_pSendInfo[i].iLenght;

		m_pSendInfo[i].iSum = iSum;

		::CreateThread(NULL,NULL,(LPTHREAD_START_ROUTINE)ThreadProcDynamic,&m_pSendInfo[i],NULL,NULL);
	}

	dlgInfo.DoModal();

	delete[] m_pSendInfo;
}


/*				///固定5线程发送

void CDlgMesSet::OnBnClickedButtonMultithread()
{
	std::vector<CString> vecFilePathList;

	SYSTEMTIME currentTime;

	CString strMessage;

	if (_T("")==m_strLocalFile)
	{
		return;
	}
	GetFilePath(vecFilePathList,m_strLocalFile);

	int iCount = vecFilePathList.size();
	strMessage.Format("共有%d个文件,确认要上传全部文件？",iCount);

	if (IDYES != MessageBox(strMessage,_T("请确认是否上传文件夹"),MB_ICONEXCLAMATION|MB_YESNO ))
	{
		return;
	}

	dlgInfo.m_iCount = iCount;

	m_vecFilePathList = vecFilePathList;

	GetLocalTime(&currentTime);

	strMessage.Format(_T("%4d年%2d月%2d日%2d时%2d分%2d秒%d毫秒\t线程总数：\t%d\t文件数目：\t%d\n"),currentTime.wYear,currentTime.wMonth,currentTime.wDay,currentTime.wHour,currentTime.wMinute,
		currentTime.wSecond,currentTime.wMilliseconds,THREADCOUNT,iCount);

	m_RealMes->m_record.writeMSG(_T("./Log/AssignmentThreadRecord.txt"),strMessage);

	for (int i = 0; i < THREADCOUNT ;i++)
	{
		m_sendInfo[i].id = i;

		m_sendInfo[i].pDlg = this;

		m_sendInfo[i].iLenght = iCount / THREADCOUNT + 1;

		::CreateThread(NULL,NULL,(LPTHREAD_START_ROUTINE)ThreadProcMulti,&m_sendInfo[i],NULL,NULL);
	}

	dlgInfo.DoModal();
}

*/
/*
BOOL CDlgMesSet::LocalFilePathToServerFilePath(CString const & strLocalFilePath, CString & strServerFilePath)
{
	//本地文件路径
	//Map/年/月/日/卷号/产品名称/正面/NG/WIP条码_（OK/NG）_yyyyMMddHHmmssfff.jpg；图片
	//Map/年/月/日/卷号/产品名称/WIP条码_yyyyMMddHHmmssfff.csv ；          结果文件
	//服务器文件路径
	//工厂/工序/设备厂家/设备编号/Data/年/月/日/WIP条码_yyyyMMddHHmmssfff.csv
	//工厂/工序/设备厂家/设备编号/Image/年/月/日/WIP条码_（OK/NG）_yyyyMMddHHmmssfff.jpg
	CString strRemoteFile;	//服务器文件路径
	CString strFileExtendName;	//文件扩展名
	CString strFileName;		//文件名，带扩展名
	CString strDate;			//截取时间路径
	CString strFileType;		//文件类型
	strFileName = strLocalFilePath.Right(strLocalFilePath.GetLength()-strLocalFilePath.ReverseFind('\\')-1);

	strFileExtendName = strFileName.Right(strFileName.GetLength()- strFileName.Find('.')-1);

	strDate = strLocalFilePath.Right(strLocalFilePath.GetLength()- strLocalFilePath.Find("Map\\")-4);

	strDate = strDate.Left(strDate.Find("日\\")+2);

	if (strFileExtendName == _T("csv") || strFileExtendName == _T("xls"))
	{
		strFileType.Format(_T("Data"));
	}
	else if (strFileExtendName == _T("jpg") || strFileExtendName == _T("bmp") || strFileExtendName == _T("png"))
	{
		strFileType.Format(_T("Image"));
	}
	else
	{
		strFileType.Format(_T("未知文件类型"));
	}
	//根地址 + 设备编号 + 数据类型 + 日期 + 文件名
	strServerFilePath.Format(_T("%s/%s/%s/%s/%s"),m_RealMes->GetFtpAddr(),m_strEMSN,strFileType,strDate,strFileName);
	return TRUE;
}
*/

void CDlgMesSet::OnEnKillfocusEditThreadnumber()
{
	CString strMessage;

	char pNumberOld[MAX_PATH] = {0};

	char pNumberNew[MAX_PATH] = {0};

	int iNumber = 0;

	memset(pNumberOld,0,MAX_PATH * sizeof(char));

	memset(pNumberNew,0,MAX_PATH * sizeof(char));

	m_Edit_ThreadNumber.GetWindowText(pNumberOld,MAX_PATH);

	iNumber = atoi(pNumberOld);

	if (iNumber < 2 || iNumber > 50)
	{
		itoa(m_iThreadNumber,pNumberNew,10);

		m_Edit_ThreadNumber.SetWindowText(pNumberNew);

		strMessage.Format(_T("线程数在2到50之间"));

		MessageBox(strMessage);

		return;
	}

	m_iThreadNumber = iNumber;

	itoa(m_iThreadNumber,pNumberNew,10);

	m_Edit_ThreadNumber.SetWindowText(pNumberNew);

	strMessage.Format(_T("确实使用%d个线程？"),iNumber);
	
	if (IDYES != MessageBox(strMessage,_T("请确认线程数目"),MB_ICONEXCLAMATION|MB_YESNO ))
	{
		itoa(m_iThreadCount,pNumberNew,10);

		m_Edit_ThreadNumber.SetWindowText(pNumberNew);

		return;
	}

	m_iThreadCount = m_iThreadNumber;		//最终线程个数
}


void CDlgMesSet::OnBnClickedCheckSendhttp()
{
	UpdateData(TRUE);
}


void CDlgMesSet::InitUI(void)
{
	m_strLineCode = m_RealMes->m_strLineCode;

	m_strSectionCode = m_RealMes->m_strSectionCode;

	m_strEMSN = m_RealMes->m_strEquipmentCode;

	m_strEMName = m_RealMes->m_strEquipmentName;

	m_strFactory = m_RealMes->m_strFactory;

	m_strEQM = m_RealMes->m_strEQM;

	m_Edit_cstrResourceCode = m_RealMes->m_cstrResourceCode;

	m_Edit_cstrOperatorID = m_RealMes->m_cstrOperatorID;

	m_Edit_cstrOperatorPassword = m_RealMes->m_cstrOperatorPassword;

	m_Edit_UserName = m_RealMes->m_cstrUserName;

	m_Edit_UserPassword = m_RealMes->m_cstrUserPassword;

	m_strLocalFilePath = m_RealMes->m_strLocalFilePath;

	m_strSeverFilePath = m_RealMes->m_strServerFilePath;

	m_iIntervalMinute = m_RealMes->m_intervalMinute;

	m_Edit_nHeartBeatTime = m_RealMes->m_nHeartBeatTime;

	m_Edit_nLogSaveDays = m_RealMes->m_nLogSaveDays;
	
	m_bSendFile = m_RealMes->m_nType;

	m_isSendHttpMessage = m_RealMes->m_isSendHttpMSG;

	m_bSendOK = m_RealMes->m_bSendOK;

	m_bSendNG = m_RealMes->m_bSendNG;

	m_bSendNGCrop = m_RealMes->m_bSendNGCrop;

	m_bRename = m_RealMes->m_bRename;

	m_bSendCover = m_RealMes->m_bSendCover;

	m_strLocalRootPath = m_RealMes->m_strLocalRootPath;

	m_strRootPathSymbol = m_RealMes->m_strRootPathSymbol;

	m_strRenameSymbol = m_RealMes->m_strRenameSymbol;

	m_COMBO_logType.SetCurSel(m_RealMes->m_nLogType);

	m_Edit_nMesServerPort = m_RealMes->m_nPort;

	m_Edit_cstrMesServerAddr = m_RealMes->m_strIP;

	m_Edit_cstrFtpServerAddr = m_RealMes->m_strFtpAddr;

	m_Edit_cstrFtpServerID = m_RealMes->m_strUserID;

	m_Edit_cstrFtpServerPassword = m_RealMes->m_strPwd;

	if (m_bSendFile)
	{
		m_check_sendFile.SetCheck(TRUE);
	}
	else
	{
		m_check_sendFile.SetCheck(FALSE);
	}
	if (m_bSendOK)
	{
		m_check_sendOK.SetCheck(TRUE);
	}
	else
	{
		m_check_sendOK.SetCheck(FALSE);
	}

	if (m_bSendNG)
	{
		m_check_sendNG.SetCheck(TRUE);
	}
	else
	{
		m_check_sendNG.SetCheck(FALSE);
	}

	if (m_bSendNGCrop)
	{
		m_check_sendNGCrop.SetCheck(TRUE);
	}
	else
	{
		m_check_sendNGCrop.SetCheck(FALSE);
	}

	if (m_bSendCover)
	{
		m_check_sendCover.SetCheck(TRUE);
	}
	else
	{
		m_check_sendCover.SetCheck(FALSE);
	}

	if (m_bRename)
	{
		m_check_rename.SetCheck(TRUE);
	}
	else
	{
		m_check_rename.SetCheck(FALSE);
	}

	char pNumber[MAX_PATH] = {0};

	memset(pNumber,0,MAX_PATH * sizeof(char));

	itoa(m_iThreadCount,pNumber,10);

	m_Edit_ThreadNumber.SetWindowText(pNumber);

	UpdateData(FALSE);
}


void CDlgMesSet::OnBnClickedCheckSendok()
{
	int iCheck;

	iCheck = m_check_sendOK.GetCheck();

	m_bSendOK = iCheck;
}


void CDlgMesSet::OnBnClickedCheckSendng()
{
	int iCheck;

	iCheck = m_check_sendNG.GetCheck();

	m_bSendNG = iCheck;
}


void CDlgMesSet::OnBnClickedCheckSendngcrop()
{
	int iCheck;

	iCheck = m_check_sendNGCrop.GetCheck();

	m_bSendNGCrop = iCheck;
}


void CDlgMesSet::OnBnClickedCheckRename()
{
	int iCheck;

	iCheck = m_check_rename.GetCheck();

	m_bRename = iCheck;
}


void CDlgMesSet::OnBnClickedCheckSendcover()
{
	int iCheck;

	iCheck = m_check_sendCover.GetCheck();

	m_bSendCover = iCheck;
}


void CDlgMesSet::OnBnClickedButtonSelectrootpath()
{
	TCHAR           szFolderPath[MAX_PATH] = {0};  
	CString         strFolderPath = TEXT("");  

	BROWSEINFO      sInfo;  
	::ZeroMemory(&sInfo, sizeof(BROWSEINFO));  
	sInfo.pidlRoot   = 0;  
	sInfo.lpszTitle   = _T("");		//请选择处理结果存储路径
	sInfo.ulFlags   = BIF_RETURNONLYFSDIRS|BIF_EDITBOX|BIF_DONTGOBELOWDOMAIN;  
	sInfo.lpfn     = NULL;  

	// 显示文件夹选择对话框  
	LPITEMIDLIST lpidlBrowse = ::SHBrowseForFolder(&sInfo);   
	if (lpidlBrowse != NULL)  
	{  
		// 取得文件夹名  
		if (::SHGetPathFromIDList(lpidlBrowse,szFolderPath))    
		{  
			strFolderPath = szFolderPath;  
		}  
	}  
	if(lpidlBrowse != NULL)  
	{  
		::CoTaskMemFree(lpidlBrowse);  
	} 
	m_strLocalRootPath = strFolderPath;
	UpdateData(FALSE);
}


BOOL CDlgMesSet::Save(void)
{
	UpdateData(TRUE);

	CString cstrOPLog;

	m_RealMes->m_strLineCode = m_strLineCode;
	cstrOPLog.Format("线体编号：%s",m_strLineCode);
	WriteOPLog(cstrOPLog);

	m_RealMes->m_strSectionCode = m_strSectionCode;
	cstrOPLog.Format("工段编号：%s",m_strSectionCode);
	WriteOPLog(cstrOPLog);

	m_RealMes->m_strEquipmentCode = m_strEMSN;
	cstrOPLog.Format("设备编号：%s",m_strEMSN);
	WriteOPLog(cstrOPLog);

	m_RealMes->m_strEquipmentName = m_strEMName;
	cstrOPLog.Format("设备名称：%s",m_strEMName);
	WriteOPLog(cstrOPLog);

	m_RealMes->m_strFactory = m_strFactory;
	cstrOPLog.Format("工厂：%s",m_strFactory);
	WriteOPLog(cstrOPLog);

	m_RealMes->m_strEQM = m_strEQM;
	cstrOPLog.Format("设备厂家：%s",m_strEQM);
	WriteOPLog(cstrOPLog);

	m_RealMes->m_cstrResourceCode = m_Edit_cstrResourceCode;
	cstrOPLog.Format("资源编号：%s",m_Edit_cstrResourceCode);
	WriteOPLog(cstrOPLog);

	m_RealMes->m_cstrOperatorID = m_Edit_cstrOperatorID;
	cstrOPLog.Format("操作员：%s",m_Edit_cstrOperatorID);
	WriteOPLog(cstrOPLog);

	m_RealMes->m_cstrOperatorPassword = m_Edit_cstrOperatorPassword;
	cstrOPLog.Format("操作员密码：%s",m_Edit_cstrOperatorPassword);
	WriteOPLog(cstrOPLog);

	m_RealMes->m_cstrUserName = m_Edit_UserName;

	cstrOPLog.Format("用户名：%s",m_Edit_UserName);
	WriteOPLog(cstrOPLog);

	m_RealMes->m_cstrUserPassword = m_Edit_UserPassword;
	cstrOPLog.Format("用户密码：%s",m_Edit_cstrOperatorPassword);
	WriteOPLog(cstrOPLog);

	m_RealMes->m_strLocalFilePath = m_strLocalFilePath;
	cstrOPLog.Format("本地路径：%s",m_strLocalFilePath);
	WriteOPLog(cstrOPLog);

	m_RealMes->m_strServerFilePath = m_strSeverFilePath;
	cstrOPLog.Format("服务器路径：%s",m_strSeverFilePath);
	WriteOPLog(cstrOPLog);

	 m_RealMes->m_intervalMinute = m_iIntervalMinute;
	 cstrOPLog.Format("间隔时间：%d",m_iIntervalMinute);
	 WriteOPLog(cstrOPLog);

	 m_RealMes->m_nHeartBeatTime = m_Edit_nHeartBeatTime;
	 cstrOPLog.Format("心跳间隔：%d",m_iIntervalMinute);
	 WriteOPLog(cstrOPLog);

	 m_RealMes->m_nLogSaveDays = m_Edit_nLogSaveDays;
	 cstrOPLog.Format("日志保存天数：%d",m_Edit_nLogSaveDays);
	 WriteOPLog(cstrOPLog);

	m_RealMes->m_nType = m_bSendFile;
	cstrOPLog.Format("是否发送文件：%d",m_bSendFile);
	WriteOPLog(cstrOPLog);

	m_RealMes->m_isSendHttpMSG = m_isSendHttpMessage;
	cstrOPLog.Format("是否发送HTTP：%d",m_isSendHttpMessage);
	WriteOPLog(cstrOPLog);

	m_RealMes->m_bSendOK = m_bSendOK;
	cstrOPLog.Format("是否发送OK图片：%d",m_bSendOK);
	WriteOPLog(cstrOPLog);

	m_RealMes->m_bSendNG = m_bSendNG;
	cstrOPLog.Format("是否发送NG图片：%d",m_bSendNG);
	WriteOPLog(cstrOPLog);

	m_RealMes->m_bSendNGCrop = m_bSendNGCrop;
	cstrOPLog.Format("是否发送NG抠图：%d",m_bSendNGCrop);
	WriteOPLog(cstrOPLog);

	m_RealMes->m_bRename = m_bRename;
	cstrOPLog.Format("是否发送重命名：%d",m_bRename);
	WriteOPLog(cstrOPLog);

	 m_RealMes->m_bSendCover =m_bSendCover;
	 cstrOPLog.Format("是否过滤已发送文件：%d",m_bSendCover);
	 WriteOPLog(cstrOPLog);

	m_RealMes->m_strLocalRootPath = m_strLocalRootPath;
	cstrOPLog.Format("本地根文件夹：%s",m_strLocalRootPath);
	WriteOPLog(cstrOPLog);

	m_RealMes->m_strRootPathSymbol = m_strRootPathSymbol;
	cstrOPLog.Format("本地根文件夹标志：%s",m_strRootPathSymbol);
	WriteOPLog(cstrOPLog);

	m_RealMes->m_strRenameSymbol = m_strRenameSymbol;
	cstrOPLog.Format("重命名标志：%s",m_strRenameSymbol);
	WriteOPLog(cstrOPLog);

	m_RealMes->m_nLogType = m_COMBO_logType.GetCurSel();
	cstrOPLog.Format("Mes记录日志类型：%d",m_RealMes->m_nLogType);
	WriteOPLog(cstrOPLog);

	m_RealMes->m_nPort = m_Edit_nMesServerPort;
	cstrOPLog.Format("Mes端口：%d",m_RealMes->m_nPort);
	WriteOPLog(cstrOPLog);

	m_RealMes->m_strIP = m_Edit_cstrMesServerAddr;
	cstrOPLog.Format("MesIP：%s",m_RealMes->m_strIP);
	WriteOPLog(cstrOPLog);

	m_RealMes->m_strFtpAddr = m_Edit_cstrFtpServerAddr;
	cstrOPLog.Format("FTP服务器IP：%s",m_RealMes->m_strFtpAddr);
	WriteOPLog(cstrOPLog);

	m_RealMes->m_strUserID = m_Edit_cstrFtpServerID;
	cstrOPLog.Format("FTP账号：%s",m_RealMes->m_strUserID);
	WriteOPLog(cstrOPLog);

	m_RealMes->m_strPwd = m_Edit_cstrFtpServerPassword;
	cstrOPLog.Format("MesFTP密码：%s",m_RealMes->m_strPwd);
	WriteOPLog(cstrOPLog);

	m_RealMes->SetMesAddrAndPort();

	m_RealMes->m_record.m_nLogType = m_RealMes->m_nLogType;

	m_RealMes->WriteParam();

	if ( !m_RealMes->m_cJsonRecipes.IsEmpty())
	{

		m_RealMes->m_cJsonRecipes.Replace("ProductCode",m_RealMes->m_strProductCode.GetString());

		m_RealMes->m_cJsonRecipes.Replace("Version",m_RealMes->m_strRecipeVison.GetString());

		m_RealMes->m_cJsonRecipes.Replace("LineCode",m_RealMes->m_strLineCode.GetString());

		m_RealMes->m_cJsonRecipes.Replace("SectionCode",m_RealMes->m_strSectionCode.GetString());

		m_RealMes->m_cJsonRecipes.Replace("EquipmentCode",m_RealMes->m_strEquipmentCode.GetString());
	}

	MessageBox(_T("参数保存成功！"));

	return TRUE;
}




void CDlgMesSet::OnBnClickedButtonUnrename()
{
	TCHAR           szFolderPath[MAX_PATH] = {0};  
	CString         strFolderPath = TEXT("");  

	BROWSEINFO      sInfo;  
	::ZeroMemory(&sInfo, sizeof(BROWSEINFO));  
	sInfo.pidlRoot   = 0;  
	sInfo.lpszTitle   = _T("");		//请选择处理结果存储路径
	sInfo.ulFlags   = BIF_RETURNONLYFSDIRS|BIF_EDITBOX|BIF_DONTGOBELOWDOMAIN;  
	sInfo.lpfn     = NULL;  

	// 显示文件夹选择对话框  
	LPITEMIDLIST lpidlBrowse = ::SHBrowseForFolder(&sInfo);   
	if (lpidlBrowse != NULL)  
	{  
		// 取得文件夹名  
		if (::SHGetPathFromIDList(lpidlBrowse,szFolderPath))    
		{  
			strFolderPath = szFolderPath;  
		}  
	}  
	if(lpidlBrowse != NULL)  
	{  
		::CoTaskMemFree(lpidlBrowse);  
	} 

	m_RealMes->UNRename(strFolderPath);


	MessageBox(_T("删除文件标记成功!"));
}


void CDlgMesSet::OnBnClickedCheckSendfile()
{
	int iCheck;

	iCheck = m_check_sendFile.GetCheck();

	m_bSendFile = iCheck;
}


void CDlgMesSet::OnBnClickedButtonRecipeset()
{
	// TODO: 在此添加控件通知处理程序代码

	CDlgRecipes dlg;


	try
	{
		dlg.m_pRealMes = this->m_RealMes;
	}
	catch (...)
	{
	
	}
	try
	{

		dlg.DoModal();

	}
	catch (...)
	{
		
	}

}


void CDlgMesSet::OnBnClickedButtonChechrecipeversion()
{
	AfxBeginThread((AFX_THREADPROC)ThreadCheckRecipeVersion,this);
}

void CDlgMesSet::CheckRecipeVersion()
{
	CString cstrMessage;

	std::string strResponse;

	int iRet = 0;

	if(FALSE)
	{
		iRet = m_RealMes->CHeckPrecipeVersion(strResponse);
	}
	else
	{
		iRet = m_RealMes->Soap_CheckRecipeVersion(strResponse);
	}

	if (200 == iRet)
	{
		cstrMessage.Format(_T("配方校验成功成功！\n配方版本正确！\n"));
	}
	else
	{
		cstrMessage.Format(_T("配方校验失败！\n返回信息：%s\n"),strResponse.c_str());
	}

	MessageBox(cstrMessage,_T("配方校验结果"), MB_OK);
}

void CDlgMesSet::WriteOPLog(CString cstrMessage)
{
	CString cstrTemp;
	cstrTemp.Format("Mes设置：%s",cstrMessage);
	m_RealMes->Log(cstrTemp,"OPERATERLOG");
}
